package com.jvyou.app.ds.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.jvyou.app.common.domain.model.Result;
import com.jvyou.app.common.enums.HttpCodeEnum;
import com.jvyou.app.ds.domain.entity.AnswerSession;
import com.jvyou.app.ds.service.AnswerSessionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * (AnswerSesson)表控制层
 *
 * @author 橘柚
 * @since 2025-04-21 20:38:17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/answerSesson")
public class AnswerSessionController {

    private final AnswerSessionService answerSessionService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @SaCheckPermission("ds:answerSesson:get")
    public Result<AnswerSession> selectOne(@PathVariable Long id) {
        return Result.success(answerSessionService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param answerSession 实体对象
     * @return 新增结果
     */
    @PostMapping
    @SaIgnore
    public Result<AnswerSession> insert(@RequestBody AnswerSession answerSession) {
        return Result.success(answerSessionService.addAnswerSession(answerSession));
    }

    /**
     * 修改数据
     *
     * @param answerSession 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("ds:answerSesson:update")
    public Result<Boolean> updateById(@RequestBody AnswerSession answerSession) {
        boolean success = answerSessionService.updateById(answerSession);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }


    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("ds:answerSesson:delete")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = answerSessionService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }

}

